﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TempHum.service
{
    public partial class modbusConf : Form
    {
       public  SerialPort serialPort = new SerialPort();
        public static int id = 1;
        public modbusConf()
        {
            InitializeComponent();
        }

        private void modbus配置_Load(object sender, EventArgs e)
        {

        }

  

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            serialPort.BaudRate = int.Parse(comboBox1.SelectedItem.ToString());
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            serialPort.DataBits = int.Parse(comboBox2.SelectedItem.ToString());
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox3.SelectedIndex == 0) serialPort.Parity = Parity.None;
            if (comboBox3.SelectedIndex == 1) serialPort.Parity = Parity.Odd;
            if (comboBox3.SelectedIndex == 1) serialPort.Parity = Parity.Even;
        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox4.SelectedIndex == 0) serialPort.StopBits = StopBits.One;
            if (comboBox4.SelectedIndex == 1) serialPort.StopBits = StopBits.Two;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            id = (int)numericUpDown1.Value;
        }
    }
}
